www.gusucode.com > VC++网络版的打字软件源程序-源码程序 > VC++网络版的打字软件源程序-源码程序\code\TypeClt V2.0\SocketInfo.cpp
// SocketInfo.cpp: implementation of the CSocketInfo class. // Download by http://www.NewXing.com ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "Type.h" #include "SocketInfo.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CSocketInfo::CSocketInfo() { } CSocketInfo::~CSocketInfo() { } CString CSocketInfo::GetLocalHostName() { WORD wVersionRequested; WSADATA wsaData; char name[255]; memset(name,'\0',255); wVersionRequested = MAKEWORD( 2, 0 ); if ( WSAStartup( wVersionRequested, &wsaData ) == 0 ) { if( gethostname (name, sizeof(name)) == 0) { return name; } WSACleanup( ); } return ""; } CString CSocketInfo::GetLocalHostIP() { CString strIP(""); WORD wVersionRequested; WSADATA wsaData; char name[255]; memset(name,'\0',255); PHOSTENT hostinfo; wVersionRequested = MAKEWORD( 2, 0 ); if ( WSAStartup( wVersionRequested, &wsaData ) == 0 ) { if( gethostname ( name, sizeof(name)) == 0) { if((hostinfo = gethostbyname(name)) != NULL) { strIP= inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list); } } WSACleanup( ); } return strIP; }